<template>
  <div>
    <el-dialog title="编辑酒店信息" :visible.sync="dialogVisible" width="650px">
      <el-form :model="ggData" :inline="true">
        <div>
          <el-form-item label="管理员用户">
            <span v-if="!userInfo.nickname" style="margin-right:10px">
              {{ ggData.nickname }}
            </span>
            <span v-else style="margin-right:10px">
              {{ userInfo.nickname }}
            </span>
            <el-button type="primary" @click="adduseri()">去绑定</el-button>
          </el-form-item>
        </div>
        <el-form-item label="酒店名称">
          <el-input v-model="ggData.jdName"></el-input>
        </el-form-item>
        <el-form-item label="酒店电话">
          <el-input type="number" v-model="ggData.jdPhone"></el-input>
        </el-form-item>
        <el-form-item label="酒店地址">
          <el-input v-model="ggData.jdAddress"></el-input>
        </el-form-item>
        <!-- 回拨状态 -->
        <span>
          <el-form-item label="自动回拨">
            <el-select
              v-model="ggData.isCallTime"
              placeholder="是否设置自动回拨时间"
              style="width:200px"
            >
              <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </span>
        <div v-if="ggData.isCallTime == 4">
          <el-form-item label="开始时间">
            <el-date-picker
              value-format="yyyy-MM-dd HH:mm:ss"
              v-model="ggData.callTimeStart"
              type="datetime"
              placeholder="选择开始日期时间"
              style="width:200px"
            >
            </el-date-picker>
          </el-form-item>
          <span>
            <el-form-item label="结束时间">
              <el-date-picker
                value-format="yyyy-MM-dd HH:mm:ss"
                v-model="ggData.callTimeEnd"
                type="datetime"
                placeholder="选择结束日期时间"
                style="width:200px"
              >
              </el-date-picker>
            </el-form-item>
          </span>
        </div>
        <div class="textarea">
          <el-form-item label="酒店描述">
            <el-input
              type="textarea"
              :rows="3"
              placeholder="请输入内容"
              v-model="ggData.jdDescribe"
            >
            </el-input>
            <!-- <el-input v-model="ggData.jijdDescribe"></el-input> -->
          </el-form-item>
        </div>
        <!-- 上传组件 -->
        <div class="upload">
          <el-form-item label="宣传图片:" prop="jdImg">
            <div class="acea-row">
              <div
                v-for="(item, index) in ggData.jdImg"
                :key="index"
                class="pictrue"
                draggable="true"
              >
                <img class="img" :src="item" />
                <i
                  v-if="!isDisabled"
                  class="el-icon-error btndel"
                  @click="handleRemove(index)"
                />
              </div>
              <div
                v-if="ggData.jdImg != [] || '' && !isDisabled"
                class="upLoadPicBox"
                @click="modalPicTap('2')"
              >
                <div class="upLoad">
                  <i class="el-icon-camera cameraIconfont" />
                </div>
              </div>
            </div>
          </el-form-item>
        </div>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submit">确 定</el-button>
      </div>
      <groggeryBoss
        ref="ggBoss"
        :userFrom="userFrom"
        :pagesize="pagesize"
        v-on:useruid="useruid"
        v-on:finduser="finduser"
      ></groggeryBoss>
    </el-dialog>
  </div>
</template>
<script>
import { editgroggeryApi } from "@/api/groggery";
import { userListApi } from "@/api/user";
import groggeryBoss from "./groggeryBoss.vue";
export default {
  name: "grogGeryAdd",
  components: { groggeryBoss },
  props: ["ggData"],
  data() {
    return {
      //回拨状态
      options: [
        {
          value: 0,
          label: "否"
        },
        {
          value: 1,
          label: "全天"
        },
        {
          value: 2,
          label: "白天"
        },
        {
          value: 3,
          label: "晚上"
        },
        {
          value: 4,
          label: "时间段"
        }
      ],
      //  用户员管理信息
      userFrom: [
        {
          page: 1,
          limit: 15,
        }
      ],
      pagesize: {
        limit: "",
        page: "",
        total: "",
        totalPage: ""
      },
      // ggedit
      dialogVisible: false,
      dialogVisibletwo: false,
      // 地址
      dialogImageUrl: "",
      //存子
      userInfo: {
        uid: "",
        nickname: ""
      },
      isDisabled: this.$route.params.isDisabled === "1" ? true : false
    };
  },
  methods: {
    //上传组件
    handleRemove(i) {
      this.ggData.jdImg.splice(i, 1);
    },
    // 点击商品图
    modalPicTap(tit, num, i, status) {
      const _this = this;
      if (_this.isDisabled) return;
      this.$modalUpload(
        function(img) {
          if (tit === "2" && !num) {
            if (img.length > 10)
              return this.$message.warning("最多选择10张图片！");
            img.map(item => {
              _this.ggData.jdImg.push(item.sattDir);
            });
          }
        },
        tit,
        "content"
      );
    },
    // 编辑提交
    async submit() {
      await editgroggeryApi(this.ggData);
      this.$message.success("修改成功");
      this.$parent.loadData();
      this.dialogVisible = false;
    },
    // 选择管理员
    async adduseri() {
      let params = {
        page:1,
        limit:15
      }
      const res = await userListApi(params);
      // const res = await userListApi(this.userFrom);
      this.userFrom = res.list;
      this.pagesize.limit = res.limit;
      this.pagesize.page = res.page;
      this.pagesize.total = res.total;
      this.pagesize.totalPage = res.totalPage;
      this.$refs.ggBoss.dialogTableVisible = true;
    },
    //子传过来的数据
    useruid(uid, nickname) {
      this.$emit("eiduser", uid);
      this.ggData.uid = uid;
      this.userInfo.nickname = nickname;
    },
    // 搜索
    finduser(userFrom) {
      this.userFrom = userFrom;
    }
  }
};
</script>

<style lang="scss" scoped>
.upload {
  display: flex;
  width: 800px;
  height: 100px;
  .pictrue {
    width: 60px;
    height: 60px;
    border: 1px dotted rgba(0, 0, 0, 0.1);
    margin-right: 10px;
    position: relative;
    cursor: pointer;
  }
  .img {
    width: 60px;
    height: 60px;
  }
  .btndel {
    position: absolute;
    z-index: 11111;
    width: 20px !important;
    height: 20px !important;
    left: 46px;
    top: -4px;
  }
}
.textarea {
  .el-form-item :last-child {
    width: 480px;
  }
}
</style>
